<template>
    <section>


        <!--添加框-->
        <el-dialog title="驳回" :visible.sync="dialogFormVisible">

            <el-form :model="addForm" ref="addForm">
                <el-form-item label="驳回类型" :label-width="formLabelWidth">
                    <el-select v-model="addForm.type" placeholder="请选择">
                        <el-option label="公司名称" value="公司名称"></el-option>
                        <el-option label="地址" value="地址"></el-option>
                        <el-option label="电话" value="电话"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="驳回原因" :label-width="formLabelWidth">
                    <el-input type="textarea" v-model="addForm.text" autocomplete="off"></el-input>
                </el-form-item>


            </el-form>

            <div slot="footer" class="dialog-footer">
                <el-button @click="resetForm('addForm')">取 消</el-button>
                <el-button type="primary" @click="onSubmit('addForm')">确 定</el-button>
            </div>
        </el-dialog>
        <!--高级查询添加-->
        <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
            <el-form :inline="true">
                <el-form-item>
                    <el-input v-model="dname" placeholder="商家"></el-input>
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" v-on:click="getUsers">查询</el-button>
                </el-form-item>

            </el-form>
        </el-col>
        <!--列表展示-->
        <el-table :data="dictionaryTypeList" highlight-current-row v-loading="listLoading"
                  @selection-change="selsChange"
                  style="width: 100%;">
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column type="index" width="50"></el-table-column>
            <el-table-column prop="name" label=" 店铺名" width="120"></el-table-column>
            <el-table-column prop="tel" label="座机" width="120"></el-table-column>
            <el-table-column prop="logo" label="Logo">
                <template scope="scope">
                    <img :src="scope.row.logo" width="50px" height="50px" class="head_pic"/>
                </template>
            </el-table-column>
            <el-table-column prop="registerTime" label="注册时间"></el-table-column>
            <el-table-column prop="state" label="状态">
                <template scope="scope">
                    <span style="color: yellow" v-if="scope.row.state===1">待激活</span>
                    <span style="color: mediumvioletred" v-else-if="scope.row.state===0">待审核</span>
                    <span style="color: red" v-else-if="scope.row.state===-1">驳回</span>
                    <span style="color: green" v-else-if="scope.row.state===2">正常</span>
                </template>
            </el-table-column>
            <el-table-column prop="address" label="地址"></el-table-column>
            <el-table-column prop="admin.username" label="店主信息"></el-table-column>
            <el-table-column label="操作">
                <template scope="scope">
                    <el-button size="small" @click="handleEdit(scope.$index, scope.row)">通过</el-button>
                    <el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">驳回</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!--工具条-->
        <el-col :span="24" class="toolbar">

            <el-button type="danger" @click="batchUpdate" :disabled="this.sels.length===0">批量通过</el-button>

            <el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="pageSize"
                           :total="total" style="float:right;">
            </el-pagination>
        </el-col>

    </section>
</template>

<script>
    export default {
        name: "Department",
        data() {
            return {
                //高级查询字段
                dname: '',
                //弹出框的标题
                title: '',
                //明细
                //类型列表展示
                dictionaryTypeList: [],
                //明细
                //页面加载
                listLoading: '',
                currentPage: 1,
                pageSize: 5,
                total: 0,

                //选中的数据
                sels: [],
                parentId: '',
                //dialog显示
                dialogFormVisible: false,
                addForm: {
                    type: '',
                    text: '',
                    shop_id: ''
                },
                formLabelWidth: '120px'
            }
        },
        methods: {
            //重置。点击取消
            resetForm1() {
                this.dialogFormVisible1 = false
            },
            //关闭子窗口
            handleClose(done) {
                this.$confirm('确认关闭？')
                    .then(_ => {
                        done();
                    })
                    .catch(_ => {
                    });
            },
            //重置。点击取消
            resetForm(addForm) {
                // this.$refs[addForm].resetFields();
                this.dialogFormVisible = false
            },
            //提交
            onSubmit(addForm) {
                //提交校验,校验成功
                console.log(this.addForm)
                this.$http.post("/check/turn", this.addForm).then(res => {
                    //关闭dialog
                    this.dialogFormVisible = false
                    //加载数据
                    this.loadData()
                })
            },
            //高级查询
            getUsers() {
                //跳转到第一页查询
                this.currentPage = 1
                this.loadData()
            },
            //通过
            handleEdit: function (index, row) {
                this.$http.post("/check/" + row.id).then(res => {
                    //加载数据
                    this.loadData()
                })

            },
            //驳回
            handleDel(index, row) {
                //row行内所有数据
                //清空表单
                for (let i in this.addForm) {
                    this.addForm[i] = ""
                }
                this.addForm.shop_id = row.id
                this.dialogFormVisible = true

            },
            //加载数据
            loadData() {
                let params = {
                    localPage: this.currentPage, //加载默认参数
                    pageSize: this.pageSize,
                    keywords: this.dname

                }
                //请求地址  then请求成功  catch请求失败
                this.$http.post("/check", params).then(res => {
                    let {data, totals} = res.data; //解构
                    this.dictionaryTypeList = data;
                    for (let x in this.dictionaryTypeList) {
                        this.dictionaryTypeList[x].logo = "http://121.37.194.36" + this.dictionaryTypeList[x].logo
                        // console.log(this.dictionaryTypeList[x].admin)

                    }
                    this.total = totals;
                }).catch()
            },
            //批量通过
            batchUpdate() {
                this.$confirm('批量通过这些数据, 是否继续?', '删除提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {//确认
                    this.$http.post("/check/batchUpdate", this.sels).then(res => {
                        console.log(res);
                        let {message, success} = res.data; //解构函数
                        if (success) {
                            this.$message({
                                message: message,
                                type: 'success'
                            });
                            this.loadData()
                        }
                    })
                }).catch(() => {
                    this.$message('已经取消');
                })
            },
            //点击分页,更改当前页
            handleCurrentChange(val) {
                this.currentPage = val;
                this.loadData()
            },
            //选择多少行的数据
            selsChange(rows) {
                this.sels = rows;
            },
            selsChange1(rows) {
                this.sels1 = rows;
            }
        },
        mounted() {
            //加载完毕之后执行
            this.loadData()
        }
    }
</script>

<style scoped>

</style>